
/*
 * This should be the only function you ever need to edit.
 * If you don't understand what it does, keep away.
 * It can cause serious burns.
 */
 
function load_defaults(){
	$( 'div#color1' ).set_default( '#efc960' );
	$( 'div#color2' ).set_default( '#a9c157' );
	$( 'div#color3' ).set_default( '#dd5f61' );
	$( 'div#color4' ).set_default( '#6fb9fa' );
	$( 'div#color5' ).set_default( '#1ce0e7' );
}

$(document).ready ( 

	/*
	 * Adds color pickers for every div.colorbox. Make sure to add the class in theme.php
	 **/
	function () {
	$('div.colorbox').each( function() {
 		$( this ).css( 'background-color', $( 'input[type=text]', this ).val());
 		var that = this; // Yeah, I think this is needed...
		$( this ).ColorPicker({
  			onChange: function ( hsb, hex, rgb ) {
    			$( that ).css( 'backgroundColor', '#' + hex );
				$( 'input[type=text]', that ).val( '#'+hex );
  			}
		});		
 	});

	/*
	 * Hide the colorpicker...
	 */  	
	$( 'div.colorpicker' ).hover( function (){}, function () { setTimeout( '$(\'div.colorpicker\').hide();', 1000 ); } );
});

/*
 * Lets add a helper function for load_defaults. Might save some lines of code.
 * Or at least lessen the risk of errors.
 */
$.fn.set_default = function(color) {
	$( this ).css( 'backgroundColor', color );
	$( 'input[type=text]', this).val( color );
};

$.fn.set_default_image = function(sel) {
	$('select', this).attr('selectedIndex', sel);
};
	